package test.my.com.myapplicationtest.recycleview_expand;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import test.my.com.myapplicationtest.R;

/**
 * Author : Cooper
 * Time : 2017/5/9  14:18
 * Description :
 */

public class ExpandRecycleViewActivity extends Activity {

    @Bind(R.id.expand_rv)
    ExpandRecycleView expandRv;

    private List<String> mStrList = new ArrayList<>();
    private MyAdapter myAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_expand_recycleview_layout);
        ButterKnife.bind(this);
        for (int i = 0; i < 20; i++) {
            mStrList.add(i + "条数据 ===");
        }
        expandRv.setIsPullToRefresh(true);
        myAdapter = new MyAdapter(expandRv,mStrList, this);
        expandRv.setPullUpListener(new ExpandRecycleView.PullUpListener() {
            @Override
            public void loadMore() {
                expandRv.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        expandRv.setFooterViewStatus(LoadingFooterView.STATUS_LOAD_COMPLETEED);
                    }
                }, 2000);
            }
        });
        expandRv.setPullDownListener(new ExpandRecycleView.PullDownListener() {
            @Override
            public void onRefresh() {
                expandRv.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        expandRv.setRefreshing(false);
                    }
                }, 2000);
            }
        });
        expandRv.setExpandAdapter(myAdapter);

    }

    class MyAdapter extends ExpandRecycleView.ExpandRecycleViewAdapter<String> {

        private Context mContext;
        private List<String> stringList;

        public MyAdapter(ExpandRecycleView expandRecycleView,List<String> mList, Context mContext) {
            expandRecycleView.super(mList, mContext);
            this.mContext = mContext;
            this.stringList = mList;
        }

        @Override
        public RecyclerView.ViewHolder createNormalViewHolder(ViewGroup parent) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_expand_recycleview_layout, null);
            return new NormalViewHolder(view);
        }


        @Override
        public void bindNormalViewHolder(RecyclerView.ViewHolder holder, int position) {
            NormalViewHolder normalViewHolder = (NormalViewHolder) holder;
            normalViewHolder.textView.setText(stringList.get(position));
        }


        class NormalViewHolder extends RecyclerView.ViewHolder {

            private TextView textView;

            public NormalViewHolder(View itemView) {
                super(itemView);

                textView = (TextView) itemView.findViewById(R.id.tv);
            }
        }
    }
}
